$.ajax({url:'m_footer.html',type:'get',async:false, cache: true,  success:function(res){$('#footer_cotainer').html($(res));}});

var API_DOMAIN = '/';
var userInfoz = {islogin:false,username:'',logo:''};
var isProd=true;

var setUserInfoHeader = function (callback) {

	  getUserInfo(function (userInfox) {
		  if(userInfox.islogin){
			  var username=userInfox.username;
			  var logo=userInfox.logo;
			  $("#min_username_container").text(username);
			  $("#login_regist_btn_container").css('display','none'); 
			  $("#user_info_header_container").css('display',''); 
			  $("#user_info_header_logo").attr("src",logo);
		  }else{
			  $("#user_info_header_container").css('display','none'); 
			  
		  }
		  
	     if (typeof callback == 'function'){
	      callback(userdata);
	    }
	  })
}

var getUserInfo = function (callback) {
	if(isProd){
		var ajaxUrl='/met/service/pub/userInfo/userInfo';
		zfesAjax.ajaxTodo(ajaxUrl, {}, function(result) {	
			if(200==result.statusCode ){  
		    	  $.extend(userInfoz, result.data.userInfo);
		    	  userInfoz.islogin=true;
		    	 if(!userInfoz.logo){
		    		 userInfoz.logo= "img/touxiang.jpg";
		    	 }
		      }
			callback(userInfoz);
		},function(data){
			//todo nothing
		}); 
		/*return;
		 request({
			    url: '/met/service/pub/userInfo/userInfo',
			    method: 'POST',
			    success: function (result) {
			      if(result.statusCode === 200){
			    	  $.extend(userInfo, result.data.userInfo);
			    	  userInfo.login=true;
			      }
			      callback(userInfo);
			    }
			  })*/
	}else{
		var userInfo={login:false,username:"admin",logo:"http://image.biaobaiju.com/uploads/20180918/15/1537256494-ZnSKMzEoBI.jpeg"};
		 callback(userInfo);
	}

	 
	
};
	
$(function(){setUserInfoHeader();});



Array.prototype.forEach = Array.prototype.forEach || function (callback) {
 var isArray = Object.prototype.toString.call(this) == '[object Array]';
 if(isArray){
	   for(var key in this){
	         if(key != 'forEach'){
	           callback.call(this[key],key,this[key],this);
	     }
	            }
	 }else{
	    throw TypeError;
 }
	};

NodeList.prototype.forEach = Array.prototype.forEach;		


    
    
/**
 * ajax请求封装
 * @param options
 */
var request = function (options) {

  if(!options.xhrFields) {
    options.xhrFields = {
      withCredentials: true
    }
  }

  if(!options.crossDomain) {
    options.crossDomain = true
  }

  if(!options.method) {
    options.method = 'POST'
  }

  if(!options.headers){
    options.headers = {
      'X-Requested-With': 'XMLHttpRequest',
      'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
    }
  }

  $.ajax(options)
}



/**
 * 上传文件
 * @param options
 */
var requestFile = function (options) {
  if(!options.xhrFields) {
    options.xhrFields = {
      withCredentials: true
    }
  }

  if(!options.crossDomain) {
    options.crossDomain = true
  }

  options.method = 'POST'
  options.contentType = false;
  options.processData = false,

  $.ajax(options)
}

var modalError = function (message) {
  alert(message);
}

function doLogout(){
  request({
    url:  "/api/auth/logout",
    success: function (data) {
      if(data.statusCode === 200){
        window.location.href = 'login.html'
      }
    }
  })
}

/**
 * 跳转页面
 * @param url
 */
var goUrl = function (url) {
  window.location.href = url
}


var getUrlParam = function(variable){
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
          var pair = vars[i].split("=");
          if(pair[0] == variable){return pair[1];}
  }
  return(false);
}


window.onscroll=function(){
    var winTop_1=document.documentElement.scrollTop;
    var winTop_2=document.body.scrollTop;
    var winTop;
    (winTop_1>winTop_2)?winTop=winTop_1:winTop=winTop_2;
    if(winTop>0){ $("#backTop").css({'display':'block'}); }
    if(winTop == 0){ $("#backTop").css({'display':'none'});}
}


